//
//  DestinationTableViewCell.m
//  LT
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DestinationTableViewCell.h"
#import "DestinationCollectionViewCell.h"
#import "DesHot_countryModel.h"
@interface DestinationTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegate>

@property(nonatomic,strong)UICollectionView *destinationCollectionView;
@end

@implementation DestinationTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
    }
    return self;
    
}

-(void)createCollectionView{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(190* WIDTHCELL, 267* WIDTHCELL);
     //flowLayout.minimumInteritemSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //flowLayout.minimumLineSpacing = 10;
    
    self.destinationCollectionView = [[UICollectionView alloc]initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
    self.destinationCollectionView.backgroundColor = [UIColor clearColor];
    self.destinationCollectionView.delegate = self;
    self.destinationCollectionView.dataSource = self;
    //取消collectionView来回滑的效果
    self.destinationCollectionView.scrollEnabled = NO;
    [self.destinationCollectionView registerClass:[DestinationCollectionViewCell class] forCellWithReuseIdentifier:@"destinationCell"];
    [self.contentView addSubview:self.destinationCollectionView ];
    
    
}

//item数量
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArray.count;
    
}


//什么时候需要从新布局子视图
-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.destinationCollectionView.frame = CGRectMake(5 * WIDTHCELL, 5 * WIDTHCELL,(self.contentView.frame.size.width - 10), (self.contentView.frame.size.height - 10));
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
   DestinationCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"destinationCell" forIndexPath:indexPath];
    cell.DesHotModel = [self.dataArray objectAtIndex:indexPath.row];
    cell.backgroundColor = [UIColor whiteColor];
   
    return cell;
  
}

//使用数组传值
-(void)setDestinationArray:(NSMutableArray *)destinationArray{
    _destinationArray = destinationArray;
    self.dataArray = [NSMutableArray array];
    self.dataArray = [NSMutableArray arrayWithArray:_destinationArray];
    [self.destinationCollectionView reloadData];

}

////增加点击方法
//-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    [[NSNotificationCenter defaultCenter]postNotificationName:@"changHUD" object:@"0"];
//    
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
//    
//    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
//    
//}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
